import random

def binary_search(nums, target):
    low, height = 0, len(nums) - 1
    while low <= height:
        mid = (low + height) // 2
        if nums[mid] == target:
            return True
        elif nums[mid] < target:
            low = mid + 1
        else:
            height = mid - 1
    return False

def compare_f(nums, target):
    for i,num in enumerate(nums):
        if num == target:
            return True
    return False

def test(n, t):
    for _ in range(t):
        nums = [random.randint(-1000, 1000) for _ in range(n)]
        nums.sort()
        target = random.randint(-1000, 1000)
        res1 = binary_search(nums, target)
        res2 = compare_f(nums, target)
        if res1 != res2:
            print("error!")
            print(f"nums: {nums}\ntarget: {target}\nres1: {res1}\nres2: {res2}")

n, t = 1000, 10000
print("测试开始!")
test(n, t)
print("测试结束!")